package com.holike.crm.bean;

import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.holike.crm.util.ParseUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by pony on 2019/11/4.
 * Version v3.0 app报表
 * 生意内参首页数据
 */
public class BusinessReferenceMainBean {
    public String timeData;
    List<SelectMonthBean> selectData;
    @SuppressWarnings("WeakerAccess")
    List<ShopBean> shopList;
    @SuppressWarnings("WeakerAccess")
    MaterialMapBean materialMap;
    @SuppressWarnings("WeakerAccess")
    CategoryMapBean categoryMap;
    @SuppressWarnings("WeakerAccess")
    HouseMapBean houseMap;
    @SuppressWarnings("WeakerAccess")
    ChannelMapBean channelMap;
    @SuppressWarnings("WeakerAccess")
    ShopTypeMapBean shopTypeMap;
    @SuppressWarnings("WeakerAccess")
    ColorMapBean colorMap;
    @SuppressWarnings("WeakerAccess")
    SeriesMapBean styleMap;
    @SuppressWarnings("WeakerAccess")
    CustomerShopMapBean inShopCustomerMap;
    @SuppressWarnings("WeakerAccess")
    CustomerShopMapBean overDealCustomerMap;
    @SuppressWarnings("WeakerAccess")
    CustomerDetailBean customerDetail;
    @SuppressWarnings("WeakerAccess")
    @SerializedName("customerEcaluateMap")
    CustomerSatisfactionMapBean customerSatisfactionMap;
    @SuppressWarnings("WeakerAccess")
    ShopDetailBean shopDetail;
    @SuppressWarnings("WeakerAccess")
    @SerializedName("dealerMap")
    DealerRankingMapBean dealerRankingMap;

    public List<SelectMonthBean> getMonList() {
        return selectData == null ? new ArrayList<>() : selectData;
    }

    public List<ShopBean> getShopList() {
        return shopList == null ? new ArrayList<>() : shopList;
    }

    public MaterialMapBean getMaterialMap() {
        return materialMap == null ? new MaterialMapBean() : materialMap;
    }

    public CategoryMapBean getCategoryMap() {
        return categoryMap == null ? new CategoryMapBean() : categoryMap;
    }

    public HouseMapBean getHouseMap() {
        return houseMap == null ? new HouseMapBean() : houseMap;
    }

    public ChannelMapBean getChannelMap() {
        return channelMap == null ? new ChannelMapBean() : channelMap;
    }

    public ShopTypeMapBean getShopTypeMap() {
        return shopTypeMap == null ? new ShopTypeMapBean() : shopTypeMap;
    }

    public ColorMapBean getColorMap() {
        return colorMap == null ? new ColorMapBean() : colorMap;
    }

    public SeriesMapBean getSeriesMap() {
        return styleMap == null ? new SeriesMapBean() : styleMap;
    }

    public CustomerShopMapBean getInShopCustomerMap() {
        return inShopCustomerMap == null ? new CustomerShopMapBean() : inShopCustomerMap;
    }

    public CustomerShopMapBean getOverDealCustomerMap() {
        return overDealCustomerMap == null ? new CustomerShopMapBean() : overDealCustomerMap;
    }

    public CustomerDetailBean getCustomerDetail() {
        return customerDetail == null ? new CustomerDetailBean() : customerDetail;
    }

    public CustomerSatisfactionMapBean getCustomerSatisfactionMap() {
        return customerSatisfactionMap == null ? new CustomerSatisfactionMapBean() : customerSatisfactionMap;
    }

    public ShopDetailBean getShopDetail() {
        return shopDetail == null ? new ShopDetailBean() : shopDetail;
    }

    public DealerRankingMapBean getDealerRankingMap() {
        return dealerRankingMap == null ? new DealerRankingMapBean() : dealerRankingMap;
    }

    public static class SelectMonthBean {
        public String name; //月份名称
        public String selectTime; //月份编码
    }

    public static class ShopBean {
        @SerializedName("shop_id")
        public String shopId;
        @SerializedName("shop_name")
        public String shopName;
    }

    public static class MultipleMapBean<T> {
        String lastYearPercent; //同比
        String lastMonthPercent; //环比
        List<T> data;

        public List<T> getData() {
            return data == null ? new ArrayList<>() : data;
        }

        public double getLastYearPercentValue() {
            return ParseUtils.parseDouble(lastYearPercent);
        }

        public double getLastMonthPercentValue() {
            return ParseUtils.parseDouble(lastMonthPercent);
        }

        public String getLastYearPercentText() {
            if (lastYearPercent == null || lastYearPercent.trim().length() == 0) return "";
            return textWrapper(lastYearPercent) + "%";
        }

        public String getLastMonthPercentText() {
            if (lastMonthPercent == null || lastMonthPercent.trim().length() == 0) return "";
            return textWrapper(lastMonthPercent) + "%";
        }
    }

    /*板类信息*/
    public static class MaterialMapBean extends MultipleMapBean<MaterialMapBean.DataBean> {

        /*板类业绩*/
        public static class DataBean {
            @SerializedName("money_origial_board")
            String originalBoard; //原态板
            @SerializedName("money_origial_board_avg")
            String originalBoardRatio; //原态板业绩占比
            @SerializedName("money_original_K_board")
            String originalKBroad; //原态K板
            @SerializedName("money_original_K_board_avg")
            String originalKBroadRatio; //原态K板业绩占比
            @SerializedName("money_granule_board_nohome")
            String granuleBoard; //颗粒板
            @SerializedName("money_granule_board_nohome_avg")
            String granuleBoardRatio;  //颗粒板业绩占比
            @SerializedName("money_granule_board_home")
            String homeParticleBoard; //家装颗粒板
            @SerializedName("money_granule_board_home_avg")
            String homeParticleBoardRatio; //家装颗粒板业绩占比
            @SerializedName("sum_money")
            String sumMoney; //总业绩

            public String getSumMoney() {
                return getPerformance(sumMoney);
            }

            public float getOriginalBoardValue() {
                return getValue(originalBoard);
            }

            public String getOriginalBoard() {
                return getPerformance(originalBoard);
            }

            public String getOriginalBoardRatio() {
                return getPercent(originalBoardRatio);
            }

            public float getOriginalKBroadValue() {
                return getValue(originalKBroad);
            }

            public String getOriginalKBroad() {
                return getPerformance(originalKBroad);
            }

            public String getOriginalKBroadRatio() {
                return getPercent(originalKBroadRatio);
            }

            public float getGranuleBoardValue() {
                return getValue(granuleBoard);
            }

            public String getGranuleBoard() {
                return getPerformance(granuleBoard);
            }

            public String getGranuleBoardRatio() {
                return getPercent(granuleBoardRatio);
            }

            public float getHomeParticleBoardValue() {
                return getValue(homeParticleBoard);
            }

            public String getHomeParticleBoard() {
                return getPerformance(homeParticleBoard);
            }

            public String getHomeParticleBoardRatio() {
                return getPercent(homeParticleBoardRatio);
            }
        }
    }

    /*品类信息*/
    public static class CategoryMapBean extends MultipleMapBean<CategoryMapBean.DataBean> {

        public static class DataBean {
            String customize; //定制
            @SerializedName("customize_avg")
            String customizeRatio; //定制业绩占比
            String cupboard; //橱柜
            @SerializedName("cupboard_avg")
            String cupboardRatio; //橱柜业绩占比
            @SerializedName("wooden_door")
            String woodenDoor; //木门
            @SerializedName("wooden_door_avg")
            String woodenDoorRatio; //木门业绩占比
            String house; //宅配
            @SerializedName("house_avg")
            String houseRatio; //宅配业绩占比
            @SerializedName("factory_price_af_dis")
            String total; //总业绩

            public float getCustomizeValue() {
                return getValue(customize);
            }

            public String getCustomize() {
                return getPerformance(customize);
            }

            public String getCustomizeRatio() {
                return getPercent(customizeRatio);
            }

            public float getCupboardValue() {
                return getValue(cupboard);
            }

            public String getCupboard() {
                return getPerformance(cupboard);
            }

            public String getCupboardRatio() {
                return getPercent(cupboardRatio);
            }

            public float getWoodenDoorValue() {
                return getValue(woodenDoor);
            }

            public String getWoodenDoor() {
                return getPerformance(woodenDoor);
            }

            public String getWoodenDoorRatio() {
                return getPercent(woodenDoorRatio);
            }

            public float getHouseValue() {
                return getValue(house);
            }

            public String getHouse() {
                return getPerformance(house);
            }

            public String getHouseRatio() {
                return getPercent(houseRatio);
            }

            public String getTotal() {
                return getPerformance(total);
            }
        }
    }

    /*空间信息*/
    public static class HouseMapBean extends MultipleMapBean<HouseMapBean.DataBean> {
        @SerializedName("sum")
        String total; //总业绩

        public String getTotal() {
            return getPerformance(total);
        }

        public static class DataBean {
            @SerializedName("house_name")
            String houseName; //空间名称
            @SerializedName("house_money")
            String houseMoney; //空间业绩
            @SerializedName("house_money_avg")
            String houseMoneyRatio; //空间业绩占比

            public String getHouseName() {
                return textWrapper(houseName);
            }

            public float getHouseMoneyValue() {
                return (float) ParseUtils.parseDouble(houseMoney);
            }

            public String getHouseMoney() {
                return getPerformance(houseMoney);
            }

            public String getHouseMoneyRatio() {
                return getPercent(houseMoneyRatio);
            }
        }
    }

    /*客户信息*/
    public static class ChannelMapBean extends MultipleMapBean<ChannelMapBean.DataBean> {

        public static class DataBean {
            String bag; //拧包入住
            @SerializedName("bag_avg")
            String bagRatio; //拧包入住业绩占比
            @SerializedName("home")
            String home; //家装
            @SerializedName("home_avg")
            String homeRatio; //家装业绩占比
            @SerializedName("new_retail")
            String newRetail; //总部线上引流
            @SerializedName("new_retail_avg")
            String newRetailRatio; //总部线上引流业绩占比
            String conventional; //常规
            @SerializedName("conventional_avg")
            String conventionalRatio; //常规业绩占比
            String wholesale; //整装
            @SerializedName("wholesale_avg")
            String wholesaleRatio; //整装业绩占比
            String traditional; //传统渠道
            @SerializedName("traditional_avg")
            String traditionalRatio; //传统渠道业绩占比
            @SerializedName("factory_price_af_dis")
            String total; //总业绩

            public String getTotal() {
                return getPerformance(total);
            }

            public float getBagValue() {
                return getValue(bag);
            }

            public String getBag() {
                return getPerformance(bag);
            }

            public double getBagRatioValue() {
                return ParseUtils.parseDouble(bagRatio);
            }

            public String getBagRatio() {
                return getPercent(bagRatio);
            }

            public float getHomeValue() {
                return getValue(home);
            }

            public String getHome() {
                return getPerformance(home);
            }

            public double getHomeRatioValue() {
                return ParseUtils.parseDouble(homeRatio);
            }

            public String getHomeRatio() {
                return getPercent(homeRatio);
            }

            public float getNewRetailValue() {
                return getValue(newRetail);
            }

            public String getNewRetail() {
                return getPerformance(newRetail);
            }

            public double getNewRetailRatioValue() {
                return ParseUtils.parseDouble(newRetailRatio);
            }

            public String getNewRetailRatio() {
                return getPercent(newRetailRatio);
            }

            public float getConventionalValue() {
                return getValue(conventional);
            }

            public String getConventional() {
                return getPerformance(conventional);
            }

            public double getConventionalRatioValue() {
                return ParseUtils.parseDouble(conventionalRatio);
            }

            public String getConventionalRatio() {
                return getPercent(conventionalRatio);
            }

            public float getWholesaleValue() {
                return getValue(wholesale);
            }

            public String getWholesale() {
                return getPerformance(wholesale);
            }

            public double getWholesaleRatioValue() {
                return ParseUtils.parseDouble(wholesaleRatio);
            }

            public String getWholesaleRatio() {
                return getPercent(wholesaleRatio);
            }

            public float getTraditionalValue() {
                return getValue(traditional);
            }

            public String getTraditional() {
                return getPerformance(traditional);
            }

            public double getTraditionalRatioValue() {
                return ParseUtils.parseDouble(traditionalRatio);
            }

            public String getTraditionalRatio() {
                return getPercent(traditionalRatio);
            }
        }
    }

    /*门店信息*/
    public static class ShopTypeMapBean extends MultipleMapBean<ShopTypeMapBean.DataBean> {
        @SerializedName("sum")
        String total; //总业绩

        public String getTotal() {
            return getPerformance(total);
        }

        public static class DataBean {
            @SerializedName("shop_type")
            String shopType; //门店类型
            @SerializedName("shop_type_money")
            String shopMoney; //门店业绩
            @SerializedName("shop_type_money_avg")
            String shopMoneyRatio; //门店业绩占比

            public String getShopType() {
                return textWrapper(shopType);
            }

            public float getMoneyValue() {
                return getValue(shopMoney);
            }

            public String getShopMoney() {
                return getPerformance(shopMoney);
            }

            public String getShopMoneyRatio() {
                return getPercent(shopMoneyRatio);
            }
        }
    }

    /*花色业绩信息*/
    public static class ColorMapBean {

        ColorMapInnerBean orderMap; //定制业绩
        ColorMapInnerBean cupboardMap; //橱柜业绩
        ColorMapInnerBean woodDoorMap; //木门业绩

        public ColorMapInnerBean getOrderMap() {
            return orderMap == null ? new ColorMapInnerBean() : orderMap;
        }

        public ColorMapInnerBean getCupboardMap() {
            return cupboardMap == null ? new ColorMapInnerBean() : cupboardMap;
        }

        public ColorMapInnerBean getWoodDoorMap() {
            return woodDoorMap == null ? new ColorMapInnerBean() : woodDoorMap;
        }

        public static class ColorMapInnerBean extends MultipleMapBean<ColorMapInnerBean.DataBean> {

            String sum; //总业绩

            public String getSum() {
                return getPerformance(sum);
            }

            public static class DataBean {
                @SerializedName("color_money")
                String colorMoney; //花色业绩
                @SerializedName("color_money_avg")
                String colorMoneyRatio; //花色业绩占比
                @SerializedName("color_small")
                String colorName; //花色名称

                public float getColorMoneyValue() {
                    return getValue(colorMoney);
                }

                public String getColorMoney() {
                    return getPerformance(colorMoney);
                }

                public String getColorMoneyRatio() {
                    return getPercent(colorMoneyRatio);
                }

                public String getColorName() {
                    return textWrapper(colorName);
                }
            }
        }
    }

    /*系列业绩信息*/
    public static class SeriesMapBean {
        SeriesMapInnerBean orderMap; //定制业绩
        SeriesMapInnerBean cupboardMap; //橱柜业绩
        SeriesMapInnerBean woodDoorMap; //木门业绩

        public SeriesMapInnerBean getOrderMap() {
            return orderMap == null ? new SeriesMapInnerBean() : orderMap;
        }

        public SeriesMapInnerBean getCupboardMap() {
            return cupboardMap == null ? new SeriesMapInnerBean() : cupboardMap;
        }

        public SeriesMapInnerBean getWoodDoorMap() {
            return woodDoorMap == null ? new SeriesMapInnerBean() : woodDoorMap;
        }

        public static class SeriesMapInnerBean extends MultipleMapBean<SeriesMapInnerBean.DataBean> {

            String sum; //总业绩

            public String getSum() {
                return getPerformance(sum);
            }

            public static class DataBean {
                @SerializedName("style_money")
                String styleMoney; //系列业绩
                @SerializedName("style_money_avg")
                String styleMoneyRatio; //系列业绩占比
                @SerializedName("style_name")
                String styleName; //系列名称

                public float getStyleMoneyValue() {
                    return getValue(styleMoney);
                }

                public String getStyleMoney() {
                    return getPerformance(styleMoney);
                }

                public String getStyleMoneyRatio() {
                    return getPercent(styleMoneyRatio);
                }

                public String getStyleName() {
                    return textWrapper(styleName);
                }
            }
        }

    }

    /*客户来源-进店客户信息*/
    public static class CustomerShopMapBean extends MultipleMapBean<CustomerShopMapBean.DataBean> {
        @SerializedName("sum")
        String sum; //总客户数

        public String getSum() {
            return textWrapper(sum) + "人";
        }

        public static class DataBean {
            public String source; //来源编码
            @SerializedName("item_name")
            String sourceName; //来源名称
            @SerializedName("dcount")
            String count; //来源客户数
            @SerializedName("dcount_avg")
            String countRatio; //来源客户数占比

            public String getSourceName() {
                return textWrapper(sourceName);
            }

            public String getCount() {
                return textWrapper(count);
            }

            public long getCountLong() {
                return ParseUtils.parseLong(count);
            }

            public String getCountRatio() {
                return getPercent(countRatio);
            }
        }
    }

    /*客户分析*/
    public static class CustomerDetailBean {
        String customerPrice; //客单价
        String customerPriceCompare; //客单价和上月对比(>0 比上月提高，=0和上月一样，<0比上月下降)
        String dealDay; //平均成交周期
        String dealDayCompare; //平均成交周期和上月对比(>0 比上月提高，=0和上月一样，<0比上月下降)
        String orderDay; //签约→下单 天数
        String installDay; //下单→已安装 天数

        public String getCustomerPrice() {
            return getPerformance(customerPrice);
        }

        public int getCustomerPriceCompare() {
            return ParseUtils.parseInt(customerPriceCompare);
        }

        public String getDealDay() {
            return textWrapper(dealDay) + "天";
        }

        public int getDealDayCompare() {
            return ParseUtils.parseInt(dealDayCompare);
        }

        public String getOrderDay() {
            return textWrapper(orderDay) + "天";
        }

        public String getInstallDay() {
            return textWrapper(installDay) + "天";
        }
    }

    /*客户满意度*/
    public static class CustomerSatisfactionMapBean {

        String evaluateCompare; //客户满意度和上月对比(>0 比上月提高，=0和上月一样，<0比上月下降)

        public int getEvaluateCompare() {
            return ParseUtils.parseInt(evaluateCompare);
        }

        DataBean data;

        public DataBean getData() {
            return data == null ? new DataBean() : data;
        }

        public static class DataBean {
            String evaluate; //客户满意度
            String delivery; //delivery
            String install; //安装满意度
            String service; //服务满意度
            String design; //设计满意度

            public String getEvaluate() {
                return textWrapper(evaluate);
            }

            public String getDelivery() {
                return textWrapper(delivery);
            }

            public String getInstall() {
                return textWrapper(install);
            }

            public String getService() {
                return textWrapper(service);
            }

            public String getDesign() {
                return textWrapper(design);
            }
        }
    }

    /*门店效益*/
    public static class ShopDetailBean {
        String areaBenefitCompare; //坪效和上月对比(>0 比上月提高，=0和上月一样，<0比上月下降)
        String areaBenefit; //坪效
        String userBenefitCompare; //人效和上月对比(>0 比上月提高，=0和上月一样，<0比上月下降)
        String userBenefit; //人效
        String salesmanBenefit; //销售人效
        String salesmanBenefitCompare; // 销售人效和上月对比(>0 比上月提高，=0和上月一样，<0比上月下降)

        public double getAreaBenefitCompare() {
            return ParseUtils.parseDouble(areaBenefitCompare);
        }

        public String getAreaBenefit() {
            return getPerformance(areaBenefit);
        }

        public double getUserBenefitCompare() {
            return ParseUtils.parseDouble(userBenefitCompare);
        }

        public String getUserBenefit() {
            return getPerformance(userBenefit);
        }

        public double getSalesmanBenefitCompare() {
            return ParseUtils.parseDouble(salesmanBenefitCompare);
        }

        public String getSalesmanBenefit() {
            return getPerformance(salesmanBenefit);
        }
    }

    /*经销商排名*/
    public static class DealerRankingMapBean {
        List<String> financeRank; //业绩排名(0:当前排名；1:同级别经销商数)
        List<String> custPriceRank; //客单价排名(0:当前排名；1:同级别经销商数)
        List<String> overDealRank;//进店成交率排名(0:当前排名；1:同级别经销商数)
        List<String> amountRank; //量尺成交排名(0:当前排名；1:同级别经销商数)
        List<String> areaRank; //坪效排名(0:当前排名；1:同级别经销商数)
        List<String> userRank; //人效排名(0:当前排名；1:同级别经销商数)
        List<String> yearFinanceRank; //今年业绩排名(按1-当前月份排)[下标0-代表1月份，下标1-代表2月份……]
        LevelBean level; //经销商等级(1-卓越区；2-优秀区；3-潜力区；4-努力区；5-危险区；)
        List<String> top3DealerName;

        public String getPerformance() {
            return getRankingText(getFinanceRank());
        }

        List<String> getFinanceRank() {
            return financeRank == null ? new ArrayList<>() : financeRank;
        }

        public String getCustomerPrice() {
            return getRankingText(getCustPriceRank());
        }

        List<String> getCustPriceRank() {
            return custPriceRank == null ? new ArrayList<>() : custPriceRank;
        }

        public String getEntryRatioRank() {
            return getRankingText(getOverDealRank());
        }

        List<String> getOverDealRank() {
            return overDealRank == null ? new ArrayList<>() : overDealRank;
        }

        public String getScaleRatioRank() {
            return getRankingText(getAmountRank());
        }

        List<String> getAmountRank() {
            return amountRank == null ? new ArrayList<>() : amountRank;
        }

        public String getEffectRank() {
            return getRankingText(getAreaRank());
        }

        List<String> getAreaRank() {
            return areaRank == null ? new ArrayList<>() : areaRank;
        }

        public String getHumanEffectRank() {
            return getRankingText(getUserRank());
        }

        List<String> getUserRank() {
            return userRank == null ? new ArrayList<>() : userRank;
        }

        String getRankingText(List<String> list) {
            return (list.size() > 0 ? list.get(0) : "-") + "/" + (list.size() > 1 ? list.get(1) : "-");
        }

        public List<String> getYearFinanceRank() {
            return yearFinanceRank == null ? new ArrayList<>() : yearFinanceRank;
        }

        public String getTop1DealerName() {
            List<String> list = getTop3DealerList();
            return list.size() > 0 ? list.get(0) : "-";
        }

        public String getTop2DealerName() {
            List<String> list = getTop3DealerList();
            return list.size() > 1 ? list.get(1) : "-";
        }

        public String getTop3DealerName() {
            List<String> list = getTop3DealerList();
            return list.size() > 2 ? list.get(2) : "-";
        }

        List<String> getTop3DealerList() {
            return top3DealerName == null ? new ArrayList<>() : top3DealerName;
        }

        public LevelBean getLevel() {
            return level == null ? new LevelBean() : level;
        }

        /*经销商等级(1-卓越区；2-优秀区；3-潜力区；4-努力区；5-危险区；)*/
        public static class LevelBean {
            public String level;
            String position;

            public double getPosition() {
                double value = ParseUtils.parseDouble(position);
                if (value > 1) {
                    value = 1;
                }
                return value;
            }
        }
    }

    private static String textWrapper(String source) {
        return TextUtils.isEmpty(source) ? "-" : source;
    }

    private static String getPerformance(String source) {
        if (TextUtils.isEmpty(source)) return "-";
        return ParseUtils.parseDouble(source) + "万";
    }

    private static String getPercent(String source) {
        return textWrapper(source) + "%";
    }

    private static float getValue(String source) {
        return (float) ParseUtils.parseDouble(source);
    }
}
